home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / SAT 2.3b4 / Demo ƒ / Zkrolly demo ƒ / Zkrolly.c < prev    next >
Text File  |  1995-01-17  |  3KB  |  110 lines

  1.  
  2. //• C translation from Pascal source file: Zkrolly.p
  3.  
  4. //• main Zkrolly;
  5. #include "SAT.h"
  6.  
  7. extern void        InitXprite(void);
  8. extern pascal void        SetupXprite(SpritePtr me);
  9. extern pascal void        HandleXprite(SpritePtr me);
  10. extern void        InitZprite(void);
  11. extern pascal void        SetupZprite(SpritePtr me);
  12. extern pascal void        HandleZprite(SpritePtr me);
  13.  
  14.     
  15. SpritePtr ignoresp, zp;
  16. WindowPtr Zwind;
  17. Rect r;
  18.  
  19. enum {
  20.     scrollSizeH = 200,
  21.     scrollSizeV = 150
  22. };
  23.  
  24. Boolean IsOptionPressed()
  25. {
  26.     KeyMap km;
  27.  
  28. //    GetKeys(&km);
  29.     GetKeys(km);
  30.     return (km[1] & 4)!=0;
  31. }
  32.  
  33. pascal Boolean Zyncho()
  34. {
  35.     Rect where, dest;
  36.     
  37.     where.top = zp->position.v;
  38.     where.left = zp->position.h;
  39.     where.left = where.left - (scrollSizeH >> 1);
  40.     where.top = where.top - (scrollSizeV >> 1);
  41.     if (where.left < 0)
  42.         where.left = 0;
  43.     if (where.top < 0)
  44.         where.top = 0;
  45.     if (where.left + scrollSizeH > gSAT.offSizeH)
  46.         where.left = gSAT.offSizeH - scrollSizeH;
  47.     if (where.top + scrollSizeV > gSAT.offSizeV)
  48.         where.top = gSAT.offSizeV - scrollSizeV;
  49.     where.bottom = where.top + scrollSizeV;
  50.     where.right = where.left + scrollSizeH;
  51.     SetRect(&dest, 0, 0, scrollSizeH, scrollSizeV);
  52.  
  53.     SATSetPortScreen();
  54.     CopyBits(&gSAT.offScreen.port->portBits, &gSAT.wind.port->portBits, &where, &dest, srcCopy, nil);
  55.  
  56. /* SATCopyBits is obsolete. For large areas, it is hardly any better
  57. than CopyBits anyway. */
  58. /*    SATCopyBitsToScreen(gSAT.offScreen, where, dest, IsOptionPressed());*/
  59. /* Note that there's hardly any speed difference between fast and safe mode when copying areas this big!*/
  60.  
  61.     return true; //• Tell SAT not to draw on-screen: we do that ourselves!.
  62. }
  63.  
  64. void SetupZwind()
  65. {
  66.     Rect zr;
  67.     SysEnvRec wrld;
  68.     
  69.     //• Since SAT hasn't been initialized, we can't use gSAT.colorFlag but 
  70.     //• have to check environs ourselves.
  71.     if ( noErr != SysEnvirons(1, &wrld))
  72.         ;//• ignore errors.
  73.     SetRect(&zr, 20, 30, 20 + scrollSizeH, 30 + scrollSizeV);
  74.     if ( wrld.hasColorQD )
  75.         Zwind = NewCWindow(0L, &zr, "\p", false, plainDBox, (WindowPtr)-1L, false, 0);
  76.     else
  77.         Zwind = NewWindow(0L, &zr, "\p", false, plainDBox, (WindowPtr)-1L, false, 0);
  78. }
  79.  
  80.  
  81. main ()
  82. {
  83.     SATInitToolbox();
  84.  
  85.     SetupZwind ();
  86.  
  87.     SetRect(&r, 0, 0, 510, 340);
  88.     SATCustomInit(128, 129, &r, Zwind, 0L, false, false, false, true, false);
  89.     InitXprite ();
  90.     InitZprite ();
  91.     ShowWindow(gSAT.wind.port);
  92.     SelectWindow(gSAT.wind.port);
  93.     SATInstallSynch(&Zyncho);
  94.     zp = SATNewSprite(0, 90, 70, &SetupZprite);
  95.     ignoresp = SATNewSprite(0, 120, 100, &SetupXprite);
  96.     ignoresp = SATNewSprite(0, 200, 160, &SetupXprite);
  97.     SATSetPortScreen();
  98.     do
  99.     {
  100.         SATRun(IsOptionPressed());
  101.     } while (! Button ());
  102.  
  103.     //• WARNING! It seems like we mess up the current device somewhere. 
  104.     //• Probably a bug in SAT (where the device setting isn't perfect 
  105.     //• yet). Let's set port and device to something nice and safe!.
  106.     SATSetPortScreen();
  107.     /* Finally, make sure we dispose of the sound channel. */
  108.     SATSoundShutup();
  109. }
  110.